<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- <link rel="shortcut icon" href="img/logo.ico" /> -->
    <title>店铺管理</title>
    <link href="plugin/date/date.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/nav.css" />
</head>

<body>
    <!--导航-->
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
                <a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
                <ul class="nav navbar-nav" id="nav">
                    <li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-newspaper-o"></i>店铺<span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a class="navlist" target="_blank" href="user.html">店铺管理</a></li>
                            <li><a class="navlist" target="_blank" href="cooperation_audit.html">合作方申请记录</a></li>
                            <li><a class="navlist" target="_blank" href="member_rewards.html">会员业务奖励</a></li>
                            <li><a class="navlist" target="_blank" href="member_reward_rules.html">会员业务奖励规则</a></li>
                            <li><a class="navlist" target="_blank" href="agency_setting.html">合作方等级</a></li>
                            <li><a class="navlist" target="_blank" href="business_reward.html">合作方业务奖励</a></li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <!-- <li><a href="change_pass.html">修改密码</a></li> -->
                            <li><a id="loginOut" href="#">退出登陆</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container-fluid">
        <div class="row bcert-box">
            <ol class="breadcrumb">
                <li><a href="javascript:;">主页</a></li>
                <li>店铺</li>
                <li class="active">店铺管理</li>
            </ol>

            <div class="table">
                <table class="table table-bordered" id="integralList">

                </table>
            </div>

            <form class="" style="padding:0">
                <div class="form-inline">
                    <label for="exampleInputEmail1">选择分类：</label><br>
                    <div class="form-group">
                        <select class="form-control goodsClassSel">

                        </select>
                    </div>&nbsp;&nbsp;
                    <div class="form-group">
                        <select class="form-control goodsClassSel">

                        </select>
                    </div>&nbsp;&nbsp;
                    <div class="form-group">
                        <select class="form-control goodsClassSel">

                        </select>
                    </div>&nbsp;&nbsp;
                </div><br>
                <div class="form-group">
                    <label for="exampleInputEmail1">分佣比例(必须为0-100的整数)：</label><br>
                    <div class="input-group col-xs-4">
                        <!-- <div class="input-group-addon">$</div> -->
                        <input type="text" class="form-control numInput" id="commisRateInput" placeholder="">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <button type="button" class="btn btn-primary" id="btnkAddStoreClass">确认</button>
            </form>
        </div>
        <!-- 分页 -->
        <!-- <nav aria-label="...">
            <div class="">
                <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
            </div>
            <ul id="example"></ul>
        </nav> -->
    </div>

    <!-- 编辑 -->
    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="entinfo">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">编辑</h4>
                </div>
                <div class="modal-body" style="overflow:auto">
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">id</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_id" placeholder="id"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">合作方名称</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" readonly="readonly" class="form-control" id="partner_name" placeholder="合作方等级名称"></div>
                    </div>
                    <!-- <div class="form-group">
  			  <label class="col-sm-4 control-label goods-lb-l">合作方等级名称</label>
  			  <div class="col-sm-8 goods-lb-r">
  				<select class="form-control drop-down" id="">
  				  <option value="0">请合作方等级名称</option>
  				  <option value="1">省级合作方</option>
  				  <option value="2">市级合作方</option>
  				  <option value="3">县级合作方</option>
  				</select>
  			  </div>
  			</div> -->
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">金牌小卫士每月新增数量（人）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="quantity" placeholder="金牌小卫士每月新增数量"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">营收（元）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="revenue" placeholder="营收"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="complete_reward" placeholder="完成业绩分成比例"></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label goods-lb-l">未完成业绩分成比例（%）</label>
                        <div class="col-sm-8 goods-lb-r"><input type="text" class="form-control" id="unfinished_bonus" placeholder="未完成业绩分成比例"></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="entBtn">确认提交</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="plugin/layer/layer.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="plugin/date/date.js"></script>
<script type="text/javascript" src="plugin/date/date.zh-CN.js"></script>
<script src="./js/ajax.js" charset="utf-8"></script>
<script>
    // var serverURL = 'http://ww.wuyoutianxia.com/wy3pt';
    $("document").ready(function() {
        integralListPaga()
        // inputEmpty()
    })

    queryGoodsClassFunc()
    function queryGoodsClassFunc() {
        $('.goodsClassSel:gt(0)').hide()
        var url = serverURL + '/platform/queryGoodsClassGcId1'
        data = {

        };
        var cbk = function (res) {
            var data = res.data;
            console.log(data);
            $('.goodsClassSel:eq(0)').empty();
            $('.goodsClassSel:eq(0)').append('<option value="0">请选择</option>')
            for(i in data){
                $('.goodsClassSel:eq(0)').append('<option value="'+data[i].gcId+'">'+data[i].gcName+'</option>')
            }
            $('.goodsClassSel:eq(0)').change(function () {
                var gcParentIdVal = $(this).val();
                console.log(gcParentIdVal);
                data = {
                    'gcParentId':gcParentIdVal
                }
                var cbk2 = function (res) {
                    $('.goodsClassSel:eq(1)').show()
                    var data = res.data;
                    $('.goodsClassSel:eq(1)').empty();
                    $('.goodsClassSel:eq(1)').append('<option value="0">请选择</option>')
                    for(i in data){
                        $('.goodsClassSel:eq(1)').append('<option value="'+data[i].gcId+'">'+data[i].gcName+'</option>')
                    }
                    $('.goodsClassSel:eq(1)').change(function () {
                        var gcParentIdVal = $(this).val();
                        // console.log(gcParentIdVal);
                        data = {
                            'gcParentId':gcParentIdVal
                        }
                        var cbk3 = function (res) {
                            $('.goodsClassSel:eq(2)').show()
                            var data = res.data;
                            $('.goodsClassSel:eq(2)').empty();
                            $('.goodsClassSel:eq(2)').append('<option value="0">请选择</option>')
                            for(i in data){
                                $('.goodsClassSel:eq(2)').append('<option value="'+data[i].gcId+'">'+data[i].gcName+'</option>')
                            }
                        }
                        ajax(
                            url,
                            data,
                            cbk3,
                            'post',
                            'json'
                        )
                    })
                }
                ajax(
                    url,
                    data,
                    cbk2,
                    'post',
                    'json'
                )
            })
        }
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    }
    function getQueryString(key) {
        var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        var result = window.location.search.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]) : null;
    }
    var storeIdVal = getQueryString('id');
    function integralListPaga() {
        var pageUrls = serverURL + '/platform/queryStoreBindClass';
        data = {
            'storeId':storeIdVal
        };
        ajax(
            pageUrls,
            data,
            pageNumList,
            'post',
            'json'
        )
    }

    //数据渲染
    function OpendList(res) {
        console.log(res);
        var result = '';
        $('#integralList').empty();
        $('#integralList').append(
            '<tr>' +
            '<th colspan="7">店铺</th>' +
            '</tr>' +
            '<tr>' +
            '<th>分类1</th>' +
            '<th>分类2</th>' +
            '<th>分类3</th>' +
            '<th>分佣金比例</th>' +
            '<th>操作</th>' +
            '</tr>'
        );
        for (i in res.data) {
            // var time = getMyDate(res.data[i].createTime);
            result +=
                '<tr>' +
                '<td>' + res.data[i].class1 + '</td>' +
                '<td>' + res.data[i].class2 + '</td>' +
                '<td>' + res.data[i].class3 + '</td>' +
                '<td><div class="input-group col-xs-4">' +
                '<input type="text" class="form-control numInput" id="" placeholder="" value="'+res.data[i].commisRate+'">' +
                '<div class="input-group-addon">%</div>' +
                '</div></td>' +
                '<td class="text-center">' +
                '<button type="button" data-id="' + res.data[i].bid + '" class="btn btn-danger btn-sm listDel">删除</button>&nbsp;&nbsp;' +
                '</td>' +
                '</tr>'
        }
        $('#integralList tbody').append(result);
        $('.numInput').each(function() {
            $(this).on('input porpertychange change', function() {
                inputControl(this);
            });
        })
    }
    //删除
    $(document).on('click', '.listDel', function() {
        var id = $(this).attr('data-id')
        console.log(id);
        layer.confirm('确定要删除这条信息吗？', {
            btn: ['确定', '取消'] //按钮
        }, function() {
            deleteList(id)
        }, function() {});
    })
    //详情
    $(document).on('click', '.listEnt', function() {
        var id = $(this).attr('data-id')
        $.ajax({
            url: serverURL + '/member/queryPartnerLevelByPrimaryKey',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': id,
            },
            success: function(data) {
                console.log(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#partner_id').val(data.data.partner_id)
                    $('#partner_name').val(data.data.partner_name)
                    $('#quantity').val(data.data.quantity)
                    $('#revenue').val(data.data.revenue)
                    $('#complete_reward').val(data.data.complete_reward)
                    $('#unfinished_bonus').val(data.data.unfinished_bonus)
                    integralListPaga();
                }
            }
        });
    })

    //修改
    $('#entBtn').click(function() {
        $.ajax({
            url: serverURL + '/member/savePartnerLevel',
            type: "post",
            dataType: "json",
            data: {
                'partner_id': $('#partner_id').val(),
                'partner_name': $('#partner_name').val(),
                'quantity': $('#quantity').val(),
                'revenue': $('#revenue').val(),
                'complete_reward': $('#complete_reward').val(),
                'unfinished_bonus': $('#unfinished_bonus').val()
            },
            success: function(data) {
                console.log(data.msg)
                layer.msg(data.msg)
                if (data.code == 400) {
                    alert("登陆超时请重新登陆")
                    window.location.href = "login.html";
                } else if (data.code == 200) {
                    $('#entinfo').modal('hide')
                    integralListPaga();
                }
            }
        });
    })

    //删除
    function deleteList(id) {
        var url = serverURL + '/platform/deleteStoreBind';
        data = {
            'bid':id
        }
        var cbk = function () {
            location.reload()
        }
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    }

    $('#btnkAddStoreClass').click(function () {
        var url = serverURL + '/platform/addStoreBindClass';
        data = {
            'class1':$('.goodsClassSel:eq(0)').val(),
            'class2':$('.goodsClassSel:eq(1)').val(),
            'class3':$('.goodsClassSel:eq(2)').val(),
            'commisRate':$('#commisRateInput').val(),
            'storeId':storeIdVal
        };
        var cbk = function (res) {
            location.reload()
        }
        console.log(data);
        ajax(
            url,
            data,
            cbk,
            'post',
            'json'
        )
    })

    $('.numInput').each(function() {
        $(this).on('input porpertychange change', function() {
            inputControl(this);
        });
    })

    //输入控制(只输入数字)
    function inputControl(obj) {
        var obj = $(obj)
        var val = obj.val();
        if(val < 0 || val > 100){
            obj.parents('.input-group').addClass('has-error');
            return
        }else{
            obj.parents('.input-group').removeClass('has-error');
        }
        if (val.length == 1) {
            obj.val(val.replace(/[^0-9]/g, ''));
        } else {
            obj.val(val.replace(/\D/g, ''));
        }

        // if(val < 0 || val > 100){
        //     return
        // }
        return;
    };
</script>

</html>
